import wx from 'weixin-js-sdk';
var that
export default {
    data () {
        return this.datainit({
            page: 1,
            loading: false,
            loaded: false,
            status: "all",
            list: []
        })
    },

    mounted: function () {
        let status = this.$route.query.status
        if (status == null) {
            status = "all"

        }
        this.status = status
        that = this
        this.check()
        that.$post('api/index/getjssdk', {
            url: window.location.href.toString(),
            apilist: 'openAddress|chooseWXPay'
        }, function (data) {
            wx.config(data);
        })
    },
    methods: {
        user_init: function (_user) {
            that.showlist()
        },
        onScroll(e) {
            let outerHeight = this.$el.querySelector('#list').clientHeight
            let innerHeight = this.$el.clientHeight
            let scrollTop = this.$el.scrollTop
            if (outerHeight - innerHeight - scrollTop < 50) {
                that.loadmore()
            }

        },
        setstatus: function (_status) {
            console.log(_status)
            that.status = _status
            that.showlist()
        },
        showlist: function () {
            this.page = 1;
            this.loading = false;
            this.loaded = false;
            that.list = []
            this.loadmore()
        },
        loadmore: function () {
            if (that.loading || that.loaded) {
                return;
            }
            that.loading = true
            this.$post("api/user_order/lists", {
                status: this.status,
                page: this.page,
                sort: this.sort
            }, function (_list) {
                for (let i in _list) {
                    that.list.push(_list[i])
                }
                if (_list.length < 10) {
                    that.loaded = true
                }
                that.$nextTick(function () {
                    that.page++
                    that.loading = false
                })
            })
        },
        confirm(orderno) {
            that.$post("api/user_order/confirm", {orderno: orderno}, function (config) {
                that.showlist()
            })
        },
        cancel(orderno) {
            that.$post("api/user_order/cancel", {orderno: orderno}, function (config) {
                that.showlist()
            })
        },
        toexplist(orderno) {
            that.$router.push({path:'/pages/order/explist',query:{orderno:orderno}});
        },

        pay(orderno){
            that.$post("api/order/pay", {orderno: orderno}, function (config) {
                config.success = function (res) {
                    that.$toast("支付成功")
                    setTimeout(function () {
                        that.$router.push({path: '/pages/order/list', query: {status: 1}});
                    }, 2000)
                }
                wx.chooseWXPay(config);
            })
        }

    },
}